<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <title>登录 - 文库管理系统</title>
  <link rel="stylesheet" href="__PUBLIC__/admin/layui/css/layui.css">
  <link rel="stylesheet" href="__PUBLIC__/admin/static/css/style.css">
  <link rel="icon" href="__PUBLIC__/admin/static/image/code.png">
</head>
<body class="login-body body">

<div class="login-box">
  <form class="layui-form layui-form-pane" method="get" action="">
    <div class="layui-form-item">
      <h3>文库管理系统</h3>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">账号：</label>
      <div class="layui-input-inline">
        <input type="text" name="username" value="" class="layui-input" lay-verify="account" placeholder="管理员账号" autocomplete="on" maxlength="20"/>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">密码：</label>
      <div class="layui-input-inline">
        <input type="password" name="password" value="" class="layui-input" lay-verify="password" placeholder="登录密码" maxlength="20"/>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">验证码：</label>
      <div class="layui-input-inline">
        <input type="number" name="verify_code" class="layui-input" value="" lay-verify="verify_code" placeholder="验证码" maxlength="4"/>
        <i id="captcha_img">{:captcha_img()}</i>

      </div>
    </div>
    <div class="layui-form-item">
      <button type="submit" class="layui-btn" lay-submit="" lay-filter="sub"  style="width:300px">立即登录</button>
    </div>
  </form>
</div>
<script type="text/javascript" src="__PUBLIC__/admin/layui/layui.js"></script>
<script type="text/javascript">
  layui.use(['form', 'layer'], function () {
    // 操作对象
    var form = layui.form, layer = layui.layer, $ = layui.jquery;

    // 验证
    form.verify({
      account: function (value) {
        if (value == "") {
          return "请输入账号";
        }
      },
      password: function (value) {
        if (value == "") {
          return "请输入密码";
        }
      },
      verify_code: function (value) {
        if (value == "") {
          return "请输入验证码";
        }
      }
    });
    //重置验证码


    // 提交
    form.on('submit(sub)', function (data) {
      // 提交到方法 默认为本身
      $.post("{:url('index/login')}",data.field,function(res){
        if(res.status == 1){
          layer.msg(res.msg,{time:1800},function(){
            location.href = "{:url('/admin')}";
          });
        }else{
          layer.msg(res.msg,{time:1800});
          $("#captcha_img img").attr('src','{:captcha_src()}?tm='+Math.random());//刷新验证码
        }
      });
      return false;
    });
  })
</script>
</body>
</html>